import { request } from '@@/plugin-request/request';
import { EmployeeBody, EmployeeListItem } from '@/pages/Employee/List/data';

export async function employeeList(params: {
  // query
  /** 当前的页码 */
  current?: number;
  /** 页面的容量 */
  pageSize?: number;
  /** 部门ID */
  orgId?: number;
}) {
  return request<{
    data: EmployeeListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/v2/enterprise/employee/list', {
    method: 'GET',
    params: {
      ...params,
      pageNum: params.current,
      // orderByColumn: "postSort",
      // isAsc: 'desc'
    },
  });
}

export async function loadEmployee(param: {
  employeeId?: number;
}): Promise<{ data: EmployeeBody }> {
  console.log(param);
  return request(`/v2/enterprise/employee/${param.employeeId}`, { method: 'GET' });
}

export async function addEmployee(param: EmployeeBody): Promise<{ data: number }> {
  return request('/v2/enterprise/employee', { method: 'POST', data: param });
}

export async function updateEmployee(param: EmployeeBody): Promise<{ data: number }> {
  return request('/v2/enterprise/employee', { method: 'PUT', data: param });
}

export async function attachedCheckEmployee(param: EmployeeBody): Promise<{ data: number }> {
  return request('/v2/enterprise/employee/attached-check', { method: 'PUT', data: param });
}
export async function attachedLeaveEmployee(employeeId: number): Promise<{ data: number }> {
  return request('/v2/enterprise/employee/attached-leave/' + employeeId, { method: 'PUT' });
}

export async function removeEmployee(data: number[], options?: { [key: string]: any }) {
  return request<Record<string, any>>(`/v2/enterprise/employee`, {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}

export async function loadEmployeeSelect(param: any) {
  return request(`/v2/enterprise/employee/select`, { method: 'POST', data: param });
}
